﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Dao;
using Spring.Data.NHibernate.Generic.Support;
using System.Collections;
using log4net;
using GoodsInvoicing.DAL.DAO;

namespace GoodsInvoicing.DAL.Hibernate
{
    public class BaseHibernate<TEntity, TId> : HibernateDaoSupport, IDAO<TEntity, TId>
    {
        public IList<TEntity> GetAll()
        {
            return HibernateTemplate.LoadAll<TEntity>();
        }

        public TEntity Get(TId id)
        {
            return HibernateTemplate.Get<TEntity>(id);

        }

        public TId Save(TEntity entity)
        {
            return (TId)HibernateTemplate.Save(entity);
        }

        public void Update(TEntity entity) 
        {
            HibernateTemplate.SaveOrUpdate(entity);
        }

        public void Delete(TEntity entity)
        {
            HibernateTemplate.Delete(entity);
        }

        public void Delete(TEntity entity, TId id) 
        {
            HibernateTemplate.Delete(Get(id));
        }

    }
}
